﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>用户</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="../Static/jquery-1.6.2.min.js" type="text/javascript"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <script src="../Static/boot.js" type="text/javascript"></script>
    <link href="../Static/demo.css" rel="stylesheet" />
    <link href="../Static/miniui/themes/blue/skin.css" rel="stylesheet" />

    <style type="text/css">
        html, body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="mini-toolbar" style="padding-bottom: 2px; padding-left: 1px; margin: 2px">
        <a class="mini-button" iconcls="icon-add" onclick="addUser()" plain="true">增加</a>
        <span class="separator"></span>
        <a class="mini-button" iconcls="icon-edit" onclick="DelUser()" plain="true">删除</a>
        <span class="separator"></span>
        <a class="mini-button" iconcls="icon-reload" onclick="reloadData()" plain="true">刷新</a>
        <input style="display:none" id="hn_type" />
        <input style="display:none" id="hn_username" />
    </div>
    <div class="mini-fit" style="padding: 0px 0px 0px 0px;">

        <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" url="/AdminMana/Ajax/AjaxService.aspx?method=GetUserPermission" multiselect="true"
             idfield="ViewToUserAccount" allowresize="true" sizelist="[10,15,20,50,100,200,300,500]"
             pagesize="20">
            <div property="columns">
                <div type="checkcolumn" width="10">
                </div>
                <div type="indexcolumn" allowsort="true">
                    序号
                </div>
                <div field="ViewToUserAccount" width="150" headeralign="center" allowsort="true">
                    账号
                </div>
                <div field="realname" width="150" headeralign="center" allowsort="true">
                    姓名
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        //grid.load({ type: mini.getbyName("type").getValue(), username: mini.getbyName("username").getValue });

        function reloadData() {
            grid.load({ type: document.getElementById("hn_type").value, username: document.getElementById("hn_username").value });
        }
        /**加载数据*********************************************************************/

        function SetData(data) {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            //mini.alert(data.OrderID);
            document.getElementById("hn_type").value = data.type;
            document.getElementById("hn_username").value = data.username;
            
            reloadData();
        }
        function addUser() {
            var type = document.getElementById("hn_type").value;
            var username = document.getElementById("hn_username").value;
            mini.open({
                url: "/AdminMana/Pub/SelectUser.html?",
                showMaxButton: false,
                title: "添加用户",
                width: 800,
                height: 500,
                onload: function () {
                    //打开子页面时传递参数
                    var iframe = this.getIFrameEl();
                    var data = { MultiSelect: "false" };
                    iframe.contentWindow.SetPara(data);
                },
                ondestroy: function (action) {
                    //返回数据时的操作
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            // var userIDs = "";
                            var usersAccount = "";
                            for (var i = 0; i < data.length; i++) {
                                usersAccount = data[i].username + "," + usersAccount;
                            }
                            //增加
                            $.ajax({
                                url: "/AdminMana/Ajax/AjaxService.aspx?method=AddUserPermission",
                                type:"post",
                                data: { username: username, type: type, viewToUserAccount: usersAccount },
                                cache: false,
                                success: function (text) {

                                    var o = mini.decode(text);
                                    var message = o.res;
                                    if (o.error != "") {
                                        message += "\r\n" + "错误信息：" + o.error;
                                        mini.alert(message);
                                    }

                                    reloadData();

                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    mini.alert(jqXHR.responseText);
                                }
                            });
                        }

                    }
                    if (action == "clear") {

                    }

                }
            });

        }
        function DelUser() {
            var rows = grid.getSelecteds();
            if (rows.length == 0) {
                alert("请先选中要删除项！");
                return;
            }
            var type = document.getElementById("hn_type").value;
            var userAccount = document.getElementById("hn_username").value;
            var viewToUserAccountArr = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                viewToUserAccountArr.push(r.ViewToUserAccount);
            }
            var viewToUserAccounts = viewToUserAccountArr.join(',');
            $.ajax({
                url: "/AdminMana/Ajax/AjaxService.aspx?method=DeleteUserPermission",
                type: "post",
                data: { userAccount: userAccount, viewToUserAccounts: viewToUserAccounts, type: type },
                cache: false,
                success: function (text) {

                    var o = mini.decode(text);
                    var message = o.res;
                    if (o.error != "") {
                        message += "\r\n" + "错误信息：" + o.error;
                        mini.alert(message);
                    }

                    reloadData();

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                }
            });
        }
    </script>
</body>

</html>
